import { createSelector } from '@ngrx/store';

import { ViewModel } from '../../models';
import { OlState } from '../reducers';
import { ViewState } from '../reducers/view.reducer';
import { getOlStateSelector } from './ol.selector';

const getViewState = createSelector(getOlStateSelector, (state: OlState) => state.view);
const getViewEntities = createSelector(getViewState, (state: ViewState) => state.entities);
const getViewCenter = createSelector(getViewEntities, (entities: ViewModel) => entities.center);
const getViewZoom = createSelector(getViewEntities, (entities: ViewModel) => entities.zoom);
const getViewMinZoom = createSelector(getViewEntities, (entities: ViewModel) => entities.minZoom);
const getViewMaxZoom = createSelector(getViewEntities, (entities: ViewModel) => entities.maxZoom);
const getViewDisabledIn = createSelector(getViewEntities, (entities: ViewModel) => entities.disabledZoomIn);
const getViewDisabledOut = createSelector(getViewEntities, (entities: ViewModel) => entities.disabledZoomOut);

export const viewSelector = {
    getViewState,
    getViewEntities,
    getViewCenter,
    getViewZoom,
    getViewMinZoom,
    getViewMaxZoom,
    getViewDisabledIn,
    getViewDisabledOut
};